package dji.ux.ext.setting.aircraft;

import androidx.annotation.NonNull;

import dji.keysdk.DJIKey;
import dji.keysdk.FlightControllerKey;
import dji.thirdparty.io.reactivex.Completable;
import dji.thirdparty.io.reactivex.Flowable;
import dji.ux.beta.base.DJISDKModel;
import dji.ux.beta.base.SchedulerProviderInterface;
import dji.ux.beta.base.WidgetModel;
import dji.ux.beta.base.uxsdkkeys.ObservableInMemoryKeyedStore;
import dji.ux.beta.util.DataProcessor;

public class ReturnAltitudeModel extends WidgetModel {
    private SchedulerProviderInterface schedulerProvider;
    private final DataProcessor<Float> returnAltitudeProcessor;

    public ReturnAltitudeModel(@NonNull DJISDKModel djiSdkModel,
                            @NonNull ObservableInMemoryKeyedStore keyedStore,
                            @NonNull SchedulerProviderInterface scheduletProviderInterface) {
        super(djiSdkModel, keyedStore);
        this.schedulerProvider = scheduletProviderInterface;
        returnAltitudeProcessor = DataProcessor.create(0.0f);
    }

    public Flowable<Float> getReturnAltitude() {
        return returnAltitudeProcessor.toFlowable();
    }

    @Override
    protected void inSetup() {
        FlightControllerKey returnAltitudeKey =
                FlightControllerKey.create(FlightControllerKey.GO_HOME_HEIGHT_IN_METERS);

        bindDataProcessor(returnAltitudeKey, returnAltitudeProcessor);
    }

    public Completable setReturnHeight(float value) {
        DJIKey returnHeightKey = FlightControllerKey.create(FlightControllerKey.GO_HOME_HEIGHT_IN_METERS);
        return djiSdkModel.setValue(returnHeightKey, value).subscribeOn(schedulerProvider.io());
    }

    @Override
    protected void inCleanup() {

    }

    @Override
    protected void updateStates() {

    }
}
